package com.traffic.api.filter.filter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Map;

import com.traffic.api.exception.ApiBizException;

public class TimeFormatFilter implements IApiFilter {
	private static final SimpleDateFormat SDF = new SimpleDateFormat("yyyyMMddHHmmss");

	public void validateFilter(Map<String, Object> params) throws ApiBizException {
		String time = String.valueOf(params.get("timeStamp"));
		try {
			Long timePara = Long.valueOf(SDF.parse(time).getTime());
			Long now = Long.valueOf(System.currentTimeMillis());

			if (timePara.longValue() > now.longValue() + 600000L) {
				throw new ApiBizException(new Throwable("(api)您填写的时间戳异常"));
			}
			now = Long.valueOf(now.longValue() - 3600000L);
			if (timePara.longValue() < now.longValue())
				throw new ApiBizException(new Throwable("(api)您填写的时间戳异常"));
		} catch (ParseException e) {
			throw new ApiBizException(new Throwable("(api)您填写的时间戳异常"));
		}
	}
}